export const getTitleConfig = (titlePosition: string, text: string) => {
  let titlePositionConfig: {
    text: string;
    left?: 'center' | 'left' | 'right' | string;
    right?: 'auto' | number | string;
    top?: 'auto' | 'middle' | 'bottom' | string;
    bottom?: 'auto' | number | string;
  } = {
    text,
  };
  switch (titlePosition) {
    case 'top':
      titlePositionConfig = {
        text,
        left: 'center',
        top: 15,
      };
      break;
    case 'bottom':
      titlePositionConfig = {
        text,
        left: 'center',
        bottom: 2,
      };
      break;
    case 'left':
      titlePositionConfig = {
        text: text.split('').join('\n'),
        top: 'middle',
        left: 15,
      };
      break;
    case 'right':
      titlePositionConfig = {
        text: text.split('').join('\n'),
        top: 'middle',
        right: 15,
      };
      break;
    default:
      break;
  }
  return titlePositionConfig;
};

export const getLegendConfig = (data, legendPosition, titlePosition) => {
  let legendPositionConfig: {
    data: [];
    left?: 'center' | 'left' | 'right' | string | number;
    right?: 'auto' | number | string;
    top?: 'auto' | 'middle' | 'bottom' | string;
    bottom?: 'auto' | number | string;
    itemWidth: number;
    itemHeight: number;
    borderRadius: number;
    orient: 'vertical' | 'horizontal';
    textStyle: {
      color: '#999';
    };
  } = {
    data,
    itemWidth: 12,
    itemHeight: 3,
    borderRadius: 2,
    orient: 'horizontal',
  };
  switch (legendPosition) {
    case 'top':
      legendPositionConfig = {
        ...legendPositionConfig,
        left: 'center',
        orient: 'horizontal',
        top: titlePosition == 'top' ? '40' : '15',
      };
      break;
    case 'bottom':
      legendPositionConfig = {
        ...legendPositionConfig,
        bottom: titlePosition == 'bottom' ? '30' : '15',
        left: 'center',
        orient: 'horizontal',
      };
      break;
    case 'left':
      legendPositionConfig = {
        ...legendPositionConfig,
        top: 'middle',
        left: titlePosition == 'left' ? 40 : 15,
        orient: 'vertical',
        width: 50,
      };
      break;
    case 'right':
      legendPositionConfig = {
        ...legendPositionConfig,
        top: '50%',
        right: titlePosition == 'right' ? 40 : 15,
        orient: 'vertical',
        width: 90,
      };
      break;
    default:
      break;
  }
  return legendPositionConfig;
};

export const getLabelConfig = (dataLabel) => {
  if (dataLabel.includes('type') && dataLabel.includes('value')) {
    return '{b}: {c}';
  } else if (dataLabel.includes('type')) {
    return '{b}';
  } else if (dataLabel.includes('value')) {
    return '{c}';
  } else {
    return '';
  }
};
